package com.swotplus.admin.web.test;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swotplus.framework.web.BaseController;
import com.swotplus.common.core.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.swotplus.system.test.service.TmpTextService;
import java.util.*;
import com.swotplus.system.test.entity.TmpText;
import com.swotplus.system.test.service.TmpTextService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hugang
 * @since 2020-06-03
 */
@Controller
@RequestMapping("/tmpText")
public class TmpTextController extends BaseController {

    @Autowired
    private TmpTextService tmpTextService;

    @RequestMapping("/*")
    public String toHtml(){
        return "";
    }

    @RequestMapping("/listData")
    @RequiresPermissions("tmpText:view")
    @ResponseBody
    public AjaxResult listData(TmpText tmpText, Integer page, Integer limit){
        QueryWrapper<TmpText> wrapper = new QueryWrapper<>(tmpText);
        Page<TmpText> pageList = tmpTextService.page(new Page<>(page,limit), wrapper);
        return AjaxResult.success("成功", (int) pageList.getTotal(),pageList.getRecords());
    }

    @RequestMapping("/add")
    @RequiresPermissions("tmpText:add")
    @ResponseBody
    public AjaxResult add(TmpText tmpText){
        return toAjax(tmpTextService.save(tmpText));
    }

    @RequestMapping("/remove")
    @RequiresPermissions("tmpText:del")
    @ResponseBody
    public  AjaxResult delBatch(String ids){
        return toAjax(tmpTextService.removeById(ids));
    }

    @RequestMapping("/edit")
    @RequiresPermissions("tmpText:edit")
    @ResponseBody
    public AjaxResult edit(TmpText tmpText){
        return toAjax(tmpTextService.updateById(tmpText));
    }

}

